package com.yundong.gongchengji.ui.mian.fragment;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yundong.gongchengji.R;
import com.yundong.gongchengji.adapter.CommonAdapter;
import com.yundong.gongchengji.adapter.ViewHolder;
import com.yundong.gongchengji.base.BaseFragment;
import com.yundong.gongchengji.util.ListToArray;
import com.yundong.gongchengji.views.NoMoveGridView;

import java.util.List;

import cn.bingoogolapple.badgeview.BGABadgeImageView;
import cn.bingoogolapple.badgeview.BGABadgeTextView;

/**
 * 我的
 * Created by ls on 2017/3/3.
 */

public class MeFragment extends BaseFragment {
    private BGABadgeImageView bgaImageviewTips;
    private TextView textUsername;
    //收藏，评价，关注
    private View titleMycollect;
    private View titleMyevaluation;
    private View titleMyfcous;
    private TextView textCollectNumber;
    private TextView textEvaluationNumber;
    private TextView textFcousNumber;
    //
    private NoMoveGridView gridviewAccount;
    //我的任务，账户余额，退出账户
    private View titleMytask;
    private View titleAccount;
    private View titleBack;
    private TextView accountYuE;//账户余额
    //参与投标，待签合同，进行中，交易成功，退款
    private BGABadgeTextView btnTender;
    private BGABadgeTextView btnSignContract;
    private BGABadgeTextView btnDuring;
    private BGABadgeTextView btnSuccessfulDeal;
    private BGABadgeTextView btnRefund;

    private int imgArray[]=new int[]{R.mipmap.img_moneydetail,R.mipmap.img_bankaccount,R.mipmap.img_moneydetail,R.mipmap.img_my_renzheng,R.mipmap.img_refund};
    private String strArray[]=new String[]{"资金明细","我的银行卡","我的简历","我的认证\n(未认证)","",""};
    @Override
    public int getRootView() {
        return R.layout.fragment_me;
    }

    @Override
    public void initView(View view) {
        gridviewAccount= (NoMoveGridView) view.findViewById(R.id.gridview_account);

        bgaImageviewTips= (BGABadgeImageView) view.findViewById(R.id.bga_imageview_tips);
        bgaImageviewTips.showCirclePointBadge();
        textUsername= (TextView) view.findViewById(R.id.text_username);

        titleMycollect= view.findViewById(R.id.title_mycollect);
        titleMyevaluation= view.findViewById(R.id.title_myevaluation);
        titleMyfcous=view.findViewById(R.id.title_myfcous);
        textCollectNumber= (TextView) titleMycollect.findViewById(R.id.text_number);
        textEvaluationNumber= (TextView) titleMyevaluation.findViewById(R.id.text_number);
        textFcousNumber= (TextView) titleMyfcous.findViewById(R.id.text_number);

        titleMytask=view.findViewById(R.id.title_mytask);
        titleAccount=view.findViewById(R.id.title_account);
        titleBack=view.findViewById(R.id.title_back);
        accountYuE= (TextView) titleAccount.findViewById(R.id.text_xianshi);

        btnTender= (BGABadgeTextView) view.findViewById(R.id.btn_tender);
        btnSignContract= (BGABadgeTextView) view.findViewById(R.id.btn_sign_contract);
        btnDuring= (BGABadgeTextView) view.findViewById(R.id.btn_during);
        btnSuccessfulDeal= (BGABadgeTextView) view.findViewById(R.id.btn_successful_deal);
        btnRefund= (BGABadgeTextView) view.findViewById(R.id.btn_refund);
    }

    @Override
    protected void initVariable() {
        titleMyfcous.findViewById(R.id.view_line).setVisibility(View.GONE);
        ((TextView)titleMyevaluation.findViewById(R.id.text_context)).setText("我的评价");
        ((TextView)titleMyfcous.findViewById(R.id.text_context)).setText("我的关注");
        ((TextView)titleMytask.findViewById(R.id.text_context)).setText("我的任务");
        ((TextView)titleAccount.findViewById(R.id.text_context)).setText("账户余额");
        ((TextView)titleBack.findViewById(R.id.text_context)).setText("退出账户");
        accountYuE.setText("￥200,000");
        accountYuE.setTextColor(ContextCompat.getColor(getActivity(),R.color.colorDiGreen));
        accountYuE.setVisibility(View.VISIBLE);
        textCollectNumber.setText(11+"");
        textEvaluationNumber.setText(12+"");
        textFcousNumber.setText(13+"");
        List<String>list= ListToArray.StringToList(strArray);
        gridviewAccount.setAdapter(new CommonAdapter<String>(getActivity(),list,R.layout.item_account) {
            @Override
            public void convert(ViewHolder helper, String item, int position) {
                if (position<4){
                    ImageView imgView=helper.getView(R.id.img_view);
                    imgView.setBackground(ContextCompat.getDrawable(getActivity(),imgArray[position]));
                    TextView textContext=helper.getView(R.id.text_context);
                    textContext.setText(item);
                    imgView.setVisibility(View.VISIBLE);
                    textContext.setVisibility(View.VISIBLE);
                }
            }

            @Override
            public boolean isEnabled(int position) {
                if (position<4){
                    return true;
                }else {
                    return false;
                }
//                return super.isEnabled(position);
            }
        });

        btnTender.showTextBadge(1+"");
        btnSignContract.showTextBadge(2+"");
        btnDuring.showTextBadge(3+"");
        btnSuccessfulDeal.showTextBadge(4+"");
        btnRefund.showTextBadge(9+"+");
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }
}
